// pcselfy.h : Declaration of the CPCSelfy

#ifdef _WIN32_WCE
#error "Neutral-threaded COM objects are not supported on Windows CE."
#endif

EXTERN_C const IID IID_IPCSelfy;

using namespace ATL;

// CPCSelfy

class ATL_NO_VTABLE CPCSelfy :
	public CComObjectRootEx<CComMultiThreadModel>,
	public CComCoClass<CPCSelfy>,
	public IDispatchImpl<IDispatch, & IID_IPCSelfy, & CAtlModule::m_libid, 0xFFFF, 0xFFFF>,
	public ISupportErrorInfo	//	TODO: not tests
//	public IDispatchImpl<IPCSelfy, &IID_IPCSelfy, &LIBID_miceshotLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
 typedef std::list<TOVERLAP> TSTDLIST;
 static POINT	g_nnCursor;	//	size of cursor
 static void CALLBACK procAPCgrabber(ULONG_PTR dwParam);
 static bool bmp2mem(PBITMAPINFO pbi, HBITMAP hBMP, LPBYTE lpBits, HDC anhdc);

private:	//	some attr and container
	unsigned		m_nBitsPixel;	//	Bits per Pixel
	VARIANT_BOOL	m_bCursor;
	HDC				m_hdcInfo;
	CPoint			m_nnSize;
	TSTDLIST		m_lstMem;

protected:
 inline HBITMAP CreateBitmap(const POINT & asize);
	HRESULT screen2file(HANDLE afile, VARIANT anopt, VARIANT_BOOL* );
	HRESULT captureScreen(HANDLE afile, const POINT & anoffset, const POINT & asize);
	bool CreateBMPFile(HANDLE afile, PBITMAPINFO pbi, LPBYTE );

public:
	CPCSelfy() : m_nBitsPixel(0), m_bCursor(VARIANT_TRUE), 
		m_hdcInfo(NULL), m_nnSize(222, 222) { }

//	DECLARE_PROTECT_FINAL_CONSTRUCT()
	void InternalFinalConstructAddRef() { InternalAddRef(); }
	void InternalFinalConstructRelease() { InternalRelease(); }
DECLARE_REGISTRY_RESOURCEID(IDR_PCSELFY)

BEGIN_COM_MAP(CPCSelfy)	//	COM_INTERFACE_ENTRY(IPCSelfy)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

// ISupportsErrorInfo
//	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
	HRESULT FinalConstruct();
	void FinalRelease();

public:
	STDMETHOD(save)(BSTR apathname, VARIANT anopt, VARIANT_BOOL* pfullscreen);
	STDMETHOD(load)(VARIANT ahandle, VARIANT anopt, VARIANT_BOOL* pfullscreen);
	STDMETHOD(get_cursor)(VARIANT_BOOL* pVal);
	STDMETHOD(put_cursor)(VARIANT_BOOL newVal);
	STDMETHOD(get_height)(LONG* pVal);
	STDMETHOD(put_height)(LONG newVal);
	STDMETHOD(get_width)(LONG* pVal);
	STDMETHOD(put_width)(LONG newVal);
	STDMETHOD(get_pixelBits)(SHORT* pVal);
	STDMETHOD(put_pixelBits)(SHORT newVal);
	STDMETHOD(get_length)(SHORT* pVal);
};
